//
//  SSWETransactionDetailViewController.m
//  ssweapp
//
//  Created by wang.jingyi on 2018/5/24.
//  Copyright © 2018年 sfit. All rights reserved.
//

#import "SSWETransactionDetailViewController.h"
#import "SSWETransactionDetailView.h"
#import "SFITSizeTool.h"
#import "SFITUITabBarViewController.h"
#import "SSWEProductMenuTableViewController.h"
#import "SSWEDeclarationTypeTableViewController.h"
#import "SSWETransactionDirectionTableViewController.h"
#import "SSWETransStatusTableViewController.h"
#import "SSWETraderApiWrapper.h"
#import "SSWEAllOCApiFields.h"

@interface SSWETransactionDetailViewController ()

//@property(nonatomic,strong) SSWETransactionDetailView *ssweTransactionDetailView;
@property (nonatomic,strong) NSMutableArray *datas;//数据源

@end

@implementation SSWETransactionDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"成交";
}

- (NSMutableArray *)datas{
    if (!_datas) {
        _datas = [[NSMutableArray alloc]init];
    }
    return _datas;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
     [self.datas removeAllObjects];
//    self.edgesForExtendedLayout = UIRectEdgeNone;
    [SFITUITabBarViewController hideTabbarForViewController:self];
//    CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - [[SFITSizeTool tool] currentStatusBarHeight] - [[SFITSizeTool tool] navigationBarHeight:self]);
//    self.ssweTransactionDetailView = [[SSWETransactionDetailView alloc]initWithFrame:rect];
//    [self.view addSubview:self.ssweTransactionDetailView];
    
//    [self initAllChildViewController];
    
    weakify(self)
    [[SSWETraderApiWrapper sharedManager] ReqQryTrade:nil Callback:^(id bizRspInfo, id resultInfo, int requestId, bool isLast, bool isError) {
        SSWEOCShfeFtdcTradeField *field = (SSWEOCShfeFtdcTradeField *)bizRspInfo;
        if(field != nil)
        {
            [self.datas addObject:[field toDictionary]];
            if (isLast == true)
            {
                dispatch_sync(dispatch_get_main_queue(), ^{
//                    __weak_self__.ssweTransactionDetailView.datas = __weak_self__.datas;
//                    [__weak_self__.ssweTransactionDetailView.detailTable reloadData];
                    
                    //[__weak_self__.ssweTransactionDetailView.menuView reload];
                });
            }
        }
    }];
}

- (void)initAllChildViewController{
    SSWEProductMenuTableViewController          *productMenuTableViewController = [[SSWEProductMenuTableViewController alloc]init];
    SSWEDeclarationTypeTableViewController      *declarationTypeTableViewController = [[SSWEDeclarationTypeTableViewController alloc]init];
    SSWETransactionDirectionTableViewController *transactionDirectionTableViewController = [[SSWETransactionDirectionTableViewController alloc]init];
    SSWETransStatusTableViewController          *transStatusTableViewController = [[SSWETransStatusTableViewController alloc]init];

    [self addChildViewController:productMenuTableViewController];
    [self addChildViewController:declarationTypeTableViewController];
    [self addChildViewController:transactionDirectionTableViewController];
    [self addChildViewController:transStatusTableViewController];
}

@end
